package com.example.barcodeapp.ui.wode.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.example.barcodeapp.R;
import com.example.barcodeapp.adapter.FragmentAdapter;
import com.example.barcodeapp.base.BaseActivity;
import com.example.barcodeapp.interfaces.IBasePersenter;
import com.example.barcodeapp.interfaces.own.IOwn;
import com.example.barcodeapp.persenter.own.WoDeJiFenPresenter;
import com.example.barcodeapp.ui.wode.bean.JiFenBean;
import com.example.barcodeapp.ui.wode.fragment.AllFragment1;
import com.example.barcodeapp.ui.wode.fragment.GetFragment;
import com.example.barcodeapp.ui.wode.fragment.HomeFragment;
import com.example.barcodeapp.ui.wode.fragment.PaymentFragment;
import com.example.barcodeapp.ui.wode.fragment.UseFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ZOrderActivity extends BaseActivity<IOwn.JiFenPresenter> implements IOwn.JiFenView {
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindView(R.id.tablayout)
    TabLayout tablayout;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_two_hundrend)
    TextView mTvTwoHundrend;
    @BindView(R.id.xiaoyu_mypoints_my_integrate)
    TextView mXiaoYuMyPointsMyIntegrate;
    @BindView(R.id.xiaoyu_mypoints_today_integrate)
    TextView mXiaoYuMypointsTodayIntegrate;

    @Override
    protected int getLayout() {
        return R.layout.activity_order;
    }

    @Override
    protected void initView() {
        ArrayList<Fragment> fragment = new ArrayList<>();
        fragment.add(new AllFragment1());
        fragment.add(new GetFragment());
        fragment.add(new UseFragment());
        FragmentAdapter fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), fragment);
        viewpager.setAdapter(fragmentAdapter);
        tablayout.setupWithViewPager(viewpager);
        tablayout.getTabAt(0).setText("全部");
        tablayout.getTabAt(1).setText("获取");
        tablayout.getTabAt(2).setText("使用");
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected WoDeJiFenPresenter initPersenter() {
        return new WoDeJiFenPresenter();
    }

    @Override
    protected void initData() {
        persenter.getJiFen(2);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    /**
     * 获取积分
     *
     * @param jiFenBean
     */
    @Override
    public void getJiFenBean(JiFenBean jiFenBean) {
        if (jiFenBean != null && jiFenBean.getData() != null){
            mTvTwoHundrend.setText(jiFenBean.getData().getJifen() + "");
            mXiaoYuMyPointsMyIntegrate.setText(jiFenBean.getData().getJifen());
            mXiaoYuMypointsTodayIntegrate.setText(jiFenBean.getData().getToday_get() + "");
        }
    }
}
